package com.spring.datasource.service;

import com.spring.datasource.config.model.User;
import com.spring.datasource.multi.Db;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Db("master")
    public void insert(User user){
        String sql = String.format("insert into t_user values (%s, '%s', %s, '%s', %s, %s, %s)", user.getId(), user.getName(),
        user.getAge(), user.getEmail(), user.getGmt_create(), user.getGmt_modified(), user.getIs_deleted());
        System.out.println(sql);
        this.jdbcTemplate.execute(sql);
    }

    @Db
    public User get(Long id){

        String sql = "select * from t_user where id = " + id;

        Map res = this.jdbcTemplate.queryForMap(sql);

        System.out.println(res);

        return new User();
    }

}
